<template>
	<view :style="{'background-color':dataobj.tabsequence?'#f8f8f8':'#fff'}" style="padding: 8px 18px;color: #aaa;font-size: 14px; display: flex;flex-direction: row;justify-content: space-between;">
		<view style="display: flex;align-items: center;color: #666;" :style="{'fontSize':clientType=='pda'?'20px':'14px'}">{{dataobj.colText}} 
			<view v-if="dataobj.tag_isNotEmpty" style="color: #F55C23;font-size: 6px;" class="iconfont icon-jiufuqianbaoicon14"> </view>
		</view>
		<view style="text-align: right;" @click="openlist" 
			:style="{'fontSize':clientType=='pda'?'20px':'14px'}"
			v-if="dataobj.tabsequence > 0 &&  dataobj.editStyle=='dddw' && !dataobj.protect && isaddedit">
			{{(dataobj.value==undefined||dataobj.value=='')?'请选择':dataobj.coldisplay}}
		</view>
		<view v-else>
			{{dataobj.coldisplay}}
		</view>
	</view>
</template>


<script>
	var util = require("../../utils/util.js");
	export default {
		props:{
			dataobj:{
				type:Object
			},
			name:{
				type:String
			},
			jsonoptions:{
				type:Object
			},
			listitemindex:{
				type:Number
			},
			listindex:{
				type:Number
			},
			listblockindex:{
				type:Number
			},
			divArea:{
				type:String
			},
			bigdatalist:{
				type:Array,
				default () {
					return []
				}
			},
			headdatalist:{
				type:Array,
				default () {
					return []
				}
			},
			pagename:{
				type:String
			},
			isaddedit:{
				type:Boolean
			},
			property:{
				type:Object
			},
			clientType:{
				type:String,
				default(){
					return ""
				}
			}
		},
		
		
		methods:{
			
			openlist(){
				console.log(this.divArea)
				var index = this.dataobj.typeindex
				var childDataObject = this.dataobj.dddw.name
				var dataColumn = this.dataobj.dddw.dataColumn
				var displayColumn = this.dataobj.dddw.displayColumn
				console.log(this.dataobj)
				var filter_column = util.gettagvalue(this.dataobj.tag,'filter_column')
				var itemchanged = util.gettagvalue(this.dataobj.tag, 'itemchanged')
				var multiselect = util.gettagvalue(this.dataobj.tag, 'multiselect')
				console.log(this.dataobj.tag)
				console.log(itemchanged)
				
				itemchanged = itemchanged.replace(/=/g, '@')  //replaceAll 有些版本不支持
				console.log(itemchanged)
				var itemfocuschanged_dddw_retrieve = util.gettagvalue(this.dataobj.tag, 'itemfocuschanged_dddw_retrieve')
				var conditions = []
				var replaceConditions = {}
				var alertcolumn = ''
				var headdatalist = this.headdatalist
				if(itemfocuschanged_dddw_retrieve != undefined && itemfocuschanged_dddw_retrieve != ''){
					console.log(itemfocuschanged_dddw_retrieve)
					var changedsemi = itemfocuschanged_dddw_retrieve.split(';')
					var bigdatalist = this.bigdatalist
					changedsemi.forEach((val)=>{
						var changedarr = val.split('=')
						var item = {}
						var value = ''
						var columnname = changedarr[1].substring(1, (changedarr[1].length-1))
						if(changedarr[0].indexOf('#') == -1){
							console.log(columnname)
							bigdatalist.forEach((val)=>{
								val.data.forEach((val2) =>{
									if(val2.name == columnname){
										value = val2.style.value
									}
								})
							})
							item['column'] = changedarr[0]
							item['value'] = value
							conditions.push(item)
						}else{
							if(columnname.indexOf('.') != -1){
								var columnarr = columnname.split('.')
								if(columnarr[0] == 'dw_mx_head'){
									headdatalist.forEach((valhead)=>{
										valhead.data.forEach((val2)=>{
											if(val2.name == columnarr[1]){
												var scolvalue = val2.style.colValue?val2.style.colValue:''
												if(scolvalue === ''){
													alertcolumn = val2.style.colText
													return
												}
												replaceConditions[changedarr[0]] = scolvalue
											}
										})
									})
								}
							}else{
								bigdatalist.forEach((val)=>{
									val.data.forEach((val2) =>{
										if(val2.name == columnname){
											var scolvalue = val2.style.colValue?val2.style.colValue:''
											if(scolvalue === ''){
												alertcolumn = val2.style.colText
												return
											}
											replaceConditions[changedarr[0]] = scolvalue
										}
									})
								})
							}
						}
					})
				}
				
				if(alertcolumn!=''){
					alertcolumn = ''
					headdatalist.forEach((valhead)=>{
						valhead.data.forEach((val2)=>{
							if(val2.style.tag_isNotEmpty && val2.style.colValue === ''){
								alertcolumn += val2.style.colText + ' '
							}
						})
					})
						
					uni.showModal({
					    title: '提示',
					    content: alertcolumn + '不能为空',
						showCancel:false
					})
					return
				}
				if(filter_column == undefined) filter_column = ''
				var colName = this.name
				uni.navigateTo({
					url: `/pages/dddwlist/dddwlist?`
						+`childDataObject=${childDataObject}`
						+`&itemchanged=${itemchanged}`
						+`&dataColumn=${dataColumn}`
						+`&displayColumn=${displayColumn}`
						+`&multiselect=${multiselect}`
						+`&divArea=${this.divArea}`
						+`&conditions=${JSON.stringify(conditions)}`
						+`&replaceConditions=${JSON.stringify(replaceConditions)}`
						+`&listindex=${this.listblockindex}`
						+`&index=${index}`
						+`&filter_column=${filter_column}`
						+`&colName=${colName}`
						+`&jsonoptions=${JSON.stringify(this.jsonoptions)}`
				})
			},
			
			updatedddwlistvalue(content,itemchanged){
				var that = this
				console.log('content',content)
				console.log('itemchanged',itemchanged)
				for(var i=0;i<content.length;i++){
					if(content[i].name == that.dataobj.dddw.dataColumn){
						var dataobj = that.dataobj
						dataobj.value = content[i].style.value
						dataobj.colValue = content[i].style.value
						dataobj.ismodified = true
						dataobj['itemcontent'] = content
						dataobj['itemchanged'] = itemchanged
						that.dataobj = dataobj
					}else if(content[i].name == that.dataobj.dddw.displayColumn){
						dataobj.coldisplay = content[i].style.value
					}
				}
				uni.$emit("updatelist", that.divArea, that.listindex, that.listblockindex, that.listitemindex, that.dataobj,this.pagename)
			},
		
		}
	}
</script>

<style>
</style>
